//#include <atom.h>
#include "stdio.h"

// The atom_weight table contains the atom radii. 

double find_atom_weight(const char element[2]) {
  int i = 0;
  int flag = 0;

  const double atom_weight[33] = {
  1.872,  /* C  -- Carbon      */
  1.507,  /* N  -- Nitrogen    */
  1.400,  /* O  -- Oxygen      */
  1.100,  /* H  -- Hydrogen    */
  1.880,  /* P  -- Phosphorus  */
  1.948,  /* Ca -- Calcium     */
  1.948,  /* Fe -- Iron        */
  1.148,  /* Zn -- Zinc        */
  1.748,  /* Cd -- Cadmium     */
  1.748,  /* I  -- Iodine      */
  1.500,  /* Mg -- Magnesium   */
  1.848,  /* S  -- Sulfur      */
  1.748,  /* Cl -- Chlorine    */
  1.548,  /* B  -- Boron       */
  1.748,  /* Br -- Bromine     */
  1.128,  /* Co -- Cobalt      */
  1.300,  /* F  -- Fluorine    */
  2.408,  /* Ba -- Barium      */
  1.548,  /* Pt -- Platinum    */
  2.200,  /* Na -- Sodium      */
  1.148,  /* Cu -- Copper      */
  2.020,  /* Sr -- Strontium   */
  1.240,  /* Ni -- Nickel      */
  2.648,  /* Rb -- Rubidium    */
  1.220,  /* Rh -- Rhodium     */
  1.980,  /* Hg -- Mercurry    */
  1.188,  /* Mn -- Manganese   */
  1.220,  /* Ir -- Iridium     */
  0.900,  /* Se -- Selenium    */
  1.608,  /* Y  -- Yttrium     */
  1.500,  /* Al -- Aluminum    */
  0.828,  /* As -- Arsenic     */
  0.628   /* Be -- Beryllium   */
  };

  const char atom_name[33][2] = {
  " C"," N"," O"," H"," P","CA","FE","ZN","CD"," I","MG"," S","CL",
  " B","BR","CO"," F","BA","PT","NA","CU","SR","NI","RB","RH","HG",
  "MN","IR","SE"," Y","AL","AS","BE"};


  while((!flag) &&(i < 33)){
    if((element[0]== atom_name[i][0])&&(element[1]==atom_name[i][1])){
      flag =1;
    }
    else {
      i++;
    }
  }
  if((flag)&&(i == 32)){
    printf("ERROR!! -- %2s\n", element);
    printf("there is no the atom in the atom_weight table\n");
    printf("Please check again \n");
    return 0;
  }
  return atom_weight[i];
}


    
double find_atom_mass(const char element[2]) {
  int i = 0;
  int flag = 0;

  const double atom_mass[33] = {
  12.011,  /* C  -- Carbon      */
  14.00674,  /* N  -- Nitrogen    */
  15.9994,  /* O  -- Oxygen      */
  01.00794,  /* H  -- Hydrogen    */
  30.973762,  /* P  -- Phosphorus  */
  40.078,  /* Ca -- Calcium     */
  55.845,    /* Fe -- Iron        */
  65.39,  /* Zn -- Zinc        */
  112.411,  /* Cd -- Cadmium     */
  126.90447,  /* I  -- Iodine      */
  24.3050,  /* Mg -- Magnesium   */
  30.066,  /* S  -- Sulfur      */
  35.4527,  /* Cl -- Chlorine    */
  10.811,  /* B  -- Boron       */
  79.904,  /* Br -- Bromine     */
  58.93320,  /* Co -- Cobalt      */
  18.9984032,  /* F  -- Fluorine    */
  137.327,  /* Ba -- Barium      */
  195.08,  /* Pt -- Platinum    */
  22.989768,  /* Na -- Sodium      */
  63.546,  /* Cu -- Copper      */
  87.62,  /* Sr -- Strontium   */
  58.6934,  /* Ni -- Nickel      */
  85.4678,  /* Rb -- Rubidium    */
  102.90550,  /* Rh -- Rhodium     */
  200.59,  /* Hg -- Mercurry    */
  54.93805,  /* Mn -- Manganese   */
  192.217,  /* Ir -- Iridium     */
  78.96,  /* Se -- Selenium    */
  88.90585,  /* Y  -- Yttrium     */
  26.981539,  /* Al -- Aluminum    */
  74.92159,  /* As -- Arsenic     */
  9.012182   /* Be -- Beryllium   */
  };

  const char atom_name[33][2] = {
  " C"," N"," O"," H"," P","CA","FE","ZN","CD"," I","MG"," S","CL",
  " B","BR","CO"," F","BA","PT","NA","CU","SR","NI","RB","RH","HG",
  "MN","IR","SE"," Y","AL","AS","BE"};


  while((!flag) &&(i < 33)){
    if((element[0]== atom_name[i][0])&&(element[1]==atom_name[i][1])){
      flag =1;
    }
    else {
      i++;
    }
  }
  if((flag)&&(i == 32)){
    printf("ERROR!! -- %2s\n", element);
    printf("there is no the atom in the atom_weight table\n");
    printf("Please check again \n");
    return 0;
  }
  return atom_mass[i];
}

  
